using Game.XH;
using UnityEngine;

namespace Game.Component.Operation
{
	public class GermObject : MonoBehaviour
	{
		public Game1Component clr;

		public Transform box;

		private bool isPlayAnim;

		private int stage;

		private float timer;

		private float originalY;

		private float targetY;

		private float curAngle;

		private float curAlpha = 1f;

		private SpriteRenderer sprite;

		private void Update()
		{
			if (!isPlayAnim)
			{
				return;
			}
			if (stage == 0)
			{
				timer += Time.deltaTime * 2f;
				base.transform.SetLocalY(Mathf.Lerp(originalY, targetY, timer));
				if (timer >= 1f)
				{
					stage = 1;
					timer = 0f;
				}
			}
			else
			{
				if (stage != 1)
				{
					return;
				}
				timer += Time.deltaTime / 2f;
				curAngle += Time.deltaTime * 360f;
				base.transform.SetLocalRotationZ(curAngle);
				sprite.SetSpriteAlpha(curAlpha - timer);
				if (timer >= 1f)
				{
					isPlayAnim = false;
					if (clr != null && box != null)
					{
						clr.PlayCompleteEfc(box.position);
					}
					Object.Destroy(base.gameObject);
				}
			}
		}

		public void PlayDestoryAnim()
		{
			if (!isPlayAnim)
			{
				isPlayAnim = true;
				originalY = base.transform.localPosition.y;
				targetY = originalY + 1f;
				Object.Destroy(base.gameObject.GetComponent<BoxCollider2D>());
				sprite = base.gameObject.GetComponent<SpriteRenderer>();
			}
		}
	}
}
